// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Start Message Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias object.value0 : start.timer
// Not sure why it skips from 0 to 4, guess there must've been a revision or smth
private alias object.value4 : start.attractTimer

private alias 0 : START_FLASH
private alias 1 : START_STARTGAME
private alias 2 : START_STARTLVLSEL
private alias 3 : START_STARTCONTINUE
private alias 4 : START_STARTATTRACT

event ObjectMain
	switch object.state
	case START_FLASH
		CheckTouchRect(0, 0, screen.xsize, screen.ysize)
		if inputPress.start == true
			checkResult = 1
		end if
		if inputPress.buttonA == true
			checkResult = 1
		end if
		if inputPress.buttonB == true
			checkResult = 1
		end if
		if inputPress.buttonC == true
			checkResult = 1
		end if
		if checkResult > -1
			if options.stageSelectFlag == true
				if checkResult > 0
					object.state = START_STARTLVLSEL
				else
					object.state = START_STARTGAME
				end if
			else
				object.state = START_STARTGAME
			end if
			PlaySfx(SfxName[Menu Select], false)
			StopMusic()
		else
			start.attractTimer++
			if start.attractTimer == 360
				object.state = START_STARTATTRACT
			end if
		end if
		break

	case START_STARTGAME
		start.timer += 8
		if start.timer == 320
			options.attractMode   = false
			player.lives 		  = 3
			player.continues 	  = 0
			player.score 		  = 0
			player.scoreBonus 	  = 50000
			lampPostID 			  = 0
			specialStage.listPos  = 0
			specialStage.emeralds = 0
			specialStage.nextZone = 0
			stage.activeList 	  = REGULAR_STAGE
			stage.listPos 		  = 0
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.timer)
		break

	case START_STARTLVLSEL
		start.timer += 8
		if start.timer == 320
			options.attractMode   = false
			player.lives 		  = 3
			player.continues 	  = 0
			player.score 		  = 0
			player.scoreBonus 	  = 50000
			lampPostID 			  = 0
			specialStage.listPos  = 0
			specialStage.emeralds = 0
			specialStage.nextZone = 0
			stage.activeList 	  = PRESENTATION_STAGE
			stage.listPos 		  = 5
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.timer)
		break

	case START_STARTCONTINUE // I dont think this state is ever used??
		start.timer += 8
		if start.timer == 320
			options.attractMode = false
			stage.listPos 		= 4
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.timer)
		break

	case START_STARTATTRACT
		start.timer += 8
		if start.timer == 320
			player.lives 		  = 3
			player.continues 	  = 0
			player.score 		  = 0
			player.scoreBonus 	  = 50000
			lampPostID 			  = 0
			specialStage.listPos  = 0
			specialStage.emeralds = 0
			specialStage.nextZone = 0

			if attract.stage == 3
				stage.activeList = SPECIAL_STAGE
				stage.listPos 	 = 0
			else
				stage.activeList = REGULAR_STAGE
				stage.listPos 	 = attract.stage
				stage.listPos 	*= 3
			end if
			attract.stage++
			attract.stage &= 3

			options.attractMode = true
			credits.screen 		= 0
			LoadStage()
		end if
		SetScreenFade(0, 0, 0, start.timer)
		break

	end switch
end event


event ObjectDraw
	object.animationTimer++
	if object.animationTimer > 59
		object.animationTimer = 0
	end if
	if object.animationTimer > 29
		DrawSpriteScreenXY(0, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Title/Title.gif")

	switch engine.deviceType
	case RETRO_STANDARD
		SpriteFrame(-52, 26, 96, 8, 1, 283)
		break
	case RETRO_MOBILE
		SpriteFrame(-60, 26, 112, 8, 1, 292)
		break
	end switch
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event